package com 
{
	import com.managers.FontManager;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	/**
	 * ...
	 * @author ...
	 */
	public class FlaText extends FlaObject
	{
		protected var _text:TextField;
		protected var _textFormat:TextFormat;
		
		override public function get width():Number {
			return _text.textWidth;
		}
		override public function set width(value:Number):void {
			_text.width = value;
		}
		
		override public function get height():Number {
			return _text.textHeight;
		}
		override public function set height(value:Number):void {
			_text.height = value;
		}
		
		override public function get tabIndex():int{
			return _text.tabIndex;
		}
		override public function set tabIndex(value:int):void{
			_text.tabIndex = value;
		}
		
		public function set text(value:String):void {
			_text.text = value;
		}
		public function get text():String {
			return _text.text;
		}
		
		public function get border():Boolean {
			return _text.border;
		}
		public function set border(value:Boolean):void {
			_text.border = value;
		}
		
		public function get multiline():Boolean {
			return _text.multiline;
		}
		public function set multiline(value:Boolean):void {
			_text.multiline = value;
			_text.autoSize = TextFieldAutoSize.LEFT;
		}
		
		public function get background():Boolean {
			return _text.background;
		}
		public function set background(value:Boolean):void {
			_text.background = value;
		}
		
		public function get backgroundColor():uint {
			return _text.backgroundColor;
		}
		public function set backgroundColor(value:uint):void {
			_text.backgroundColor = value;
		}
		
		public function set textFormat(value:TextFormat):void {
			if (_textFormat != value){
				_textFormat = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		
		public function set bold(value:Boolean):void {
			if (_textFormat.bold != value) {
				_textFormat.bold = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		public function set italic(value:Boolean):void {
			if (_textFormat.italic != value) {
				_textFormat.italic = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		public function set align(value:String):void {
			if (_textFormat.align != value) {
				_textFormat.align = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		public function set font(value:String):void {
			if (_textFormat.font != value) {
				_textFormat.font = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		public function set color(value:Object):void {
			if (_textFormat.color != value) {
				_textFormat.color = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		public function set size(value:Number):void {
			if (_textFormat.size != value) {
				_textFormat.size = value;
				_text.defaultTextFormat = _textFormat;
				_text.setTextFormat(_textFormat);
			}
		}
		public function set selectable(value:Boolean):void {
			_text.selectable = value;
		}
		
		public function FlaText(text:String = "", format:TextFormat = null) 
		{			
			if (format == null) {
				format = new TextFormat(FontManager.Default, 14, 0x000000, true);
			}
			_text = new TextField();
			
			_textFormat = format;
			_text.defaultTextFormat = format;
			_text.text = text;
			_text.mouseEnabled = false;
			_text.selectable = false;
			_text.embedFonts = true;
			//_text.autoSize = "left";
			_text.height = 30;
			_text.borderColor = 0x999999;
			
			addChild(_text);
		}
		
		public function setRegistrationPoint(regx:Number, regy:Number):void {
			_text.x = -regx;
			_text.y = -regy;
		}
		
		public override function kill():void {
			super.kill();
			removeChild(_text);
			_text = null;
			_textFormat = null;
		}
	}

}